import axios from 'axios'

import AwFormDesigner from '@/components/form-designer/index.vue'
import AwFormRender from '@/components/form-render/index.vue'
import {loadExtension} from "@/extension/extension-loader"

import '@/utils/directive'
import '@/icons'
import '@/iconfont/iconfont.css'
import globalStore from '@/utils/globalStore'

loadExtension()

AwFormDesigner.install = function (Vue) {
  Vue.component(AwFormDesigner.name, AwFormDesigner)
}

AwFormRender.install = function (Vue) {
  Vue.component(AwFormRender.name, AwFormRender)
}

const components = [
  AwFormDesigner,
  AwFormRender
]

const install = (Vue, option) => {
  window.axios = axios
  globalStore.init(option)
  components.forEach(component => {
    Vue.component(component.name, component)
  })
}

if (typeof window !== 'undefined' && window.Vue) { /* script方式引入时主动调用install方法！！ */
  install(window.Vue);
}

export default {
  install,
  globalStore,
  AwFormDesigner,
  AwFormRender
}
